class SlidingWindow<E> {

	private E[] window;
	private int start;
	private int insert;
	private int count;

	public SlidingWindow(int i) {
		window = (E[]) new Object[i];
		start = 0;
		insert = 0;
		count = 0;
	}

	public void push(E i) {
		window[insert] = i;
		count++;
		updatePointers();
	}

	public int getLength() {
		return window.length;
	}

	public boolean isEmpty() {
		return (count == 0);
	}

	public void reset() {

		for (int i = 0; i <= window.length - 1; i++) {
			window[i] = null;
		}
		insert = 0;
		start = 0;
		count = 0;
	}

	// Puts all elements into string
	public String allElements() {
		String result = "";
		for (int i = 0; i <= window.length - 1; i++) {
			if (window[i] != null)
				result = result + "\n" + window[i].toString();
		}
		return result;
	}

	public boolean checkObject(E element) {
		int i;
		for (i = 0; i <= window.length - 1 && i >= 0; i++) {
			if (window[i].equals(element)) {
				i = -2;
			}
		}
		return (i == -2);
	}

	private void updatePointers() {

		// Update start
		if (insert == window.length - 1 || insert == start - 1)
			start++;

		// Update Insert
		if (insert == window.length - 1)
			insert = 0;
		else
			insert++;
	}

}
